<template>
  <div id="app">
    <el-button type="primary">主要按钮</el-button>
    <el-table :data="list" style="width: 100%">
      <!-- <el-table-column prop="id" label="ID"> </el-table-column> -->
      <el-table-column type="index" label="序号" width="100%"> </el-table-column>
      <el-table-column prop="bookname" label="书名"> </el-table-column>
      <el-table-column prop="author" label="作者"> </el-table-column>
      <el-table-column prop="publisher" label="出版社"> </el-table-column>
      <el-table-column label="操作">
        <el-button type="danger">删除</el-button>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
// 导入封装好的方法
import { getBooksAPI } from '@/api/books.js'
export default {
  data() {
    return {
      list: []
    }
  },
  created() {
    this.getBooks()
  },
  methods: {
    async getBooks() {
      // Promise对象前，加await，即可得到Promise中的结果
      const { data: res } = await getBooksAPI()
      // console.log(res)
      if (res.status === 200) {
        this.list = res.data
      }
    }
  }
}
</script>
<style lang="less" scoped>
.el-table {
  margin-top: 20px;
}
</style>
